import { service } from "@/request";

export function login(data) {
    return service.request({
        url: "/login",
        data,
        method: "POST",
    });
}

// 账号密码登录
export function mockAdminLogin({ username }) {
    return new Promise((resovle) => {
        const data = {
            token: Math.random() * (15 - 10) + 10,
            user: {
                username: "admin",
                password: 123456,
                userPermissions: [
                    "System",
                    "Components",
                    "HomeMain",
                    "Role",
                    "Personal",
                    "TestDialogForm",
                    "TestForm",
                    "ButtonComponents",
                    "TreeTest",
                    "PdfView",
                    "TestUpload",
                    "TableTest",
                    "ContentText",
                    "EchartTest",
                    "EleLayout",
                    "AddBtn",
                    "ViewBtn",
                    "EditBtn",
                    "DelBtn",
                    "EarlyWarning",
                    "PerdonDetail"
                ],
                userId: Math.random(),
            },
        };
        // 暂时模拟，开发换成实际api
        if (username == "admin") {
            resovle(data);
        } else {
            resovle({
                token: Math.random(),
                user: {
                    username: "ssoUser",
                    password: 666666,
                    userPermissions: [
                        "HomeMain",
                        "System",
                        "Role",
                        "AddBtn",
                        'Personal'
                    ],
                    userId: Math.random(),
                },
            });
        }
    });
}

// 单点登录 --- > 根据 token 获取用户信息
export function ssoLogin({ token }) {
    return new Promise((resovle) => {
        const data = {
            token,
            user: {
                username: "ssoUser",
                password: 666666,
                userPermissions: ["HomeMain", "System", "Role"],
                userId: Math.random(),
            },
        };
        resovle(data);
    });
}
